package com.personalsystem.account.dao.impl;

import java.io.Serializable;
import java.util.List;

import org.hibernate.Query;
import org.springframework.stereotype.Component;

import com.personalsystem.account.bean.Account;
import com.personalsystem.account.dao.AccountDao;
import com.personalsystem.tool.hibernate.BaseDaoImpl;
import com.personalsystem.tool.hibernate.Finder;
import com.personalsystem.tool.page.Page;


@Component("accountDao")
public class AccountDaoImpl extends BaseDaoImpl<Account> implements AccountDao{

	@Override
	public Account deleteById(Serializable id) {
		// TODO Auto-generated method stub
		Account account=get(id);
		account.setStatus(-10);
		account=(Account)update(account);
		return account;
	}

	public Page getPage(int pageNo, int pageSize) {
		// TODO Auto-generated method stub
		Finder finder=Finder.create("from Account where status!=-10");
		return find(finder, pageNo, pageSize);
	}
	
	@SuppressWarnings("unchecked")
	public Account findAccount(String username,String password){
		Query query=getSession().createQuery("from Account where username=:username and password=:password");
		query.setString("username", username);
		query.setString("password", password);
		List list=query.list();
		if(list!=null && list.size()>0){
			return (Account)list.get(0);
		}
		return null;
	}

}
